package net.aiion.weave.spi.xml;

import java.io.OutputStream;
import java.util.Collection;
import java.util.ServiceLoader;

import net.aiion.weave.spi.xml.events.XmlEvent;

public abstract class XmlSinkFactory
{
    private static XmlSinkFactory instance;

    public XmlSinkFactory() {
    }

    public abstract XmlSink createWriter(OutputStream aOutputStream);

    public abstract XmlSink createWriter(Collection<XmlEvent> aTarget);

    public static XmlSinkFactory getInstance() {
        if (instance == null) {
            for (XmlSinkFactory xmlSinkFactory : XmlSinkFactoryServiceLoader.SERVICE_LOADER) {
                instance = xmlSinkFactory;
                break;
            }
        }

        return instance;
    }

    private static final class XmlSinkFactoryServiceLoader
    {
        private static final ServiceLoader<XmlSinkFactory> SERVICE_LOADER = ServiceLoader.load(XmlSinkFactory.class);

        private XmlSinkFactoryServiceLoader() {
        }
    }
}
